package com.kpf.springcloud.controller;

import com.kpf.springcloud.common.ResultJson;
import com.kpf.springcloud.pojo.KpfUser;
import com.kpf.springcloud.pojo.PageResult;
import com.kpf.springcloud.service.FeignClientUserServer;
import com.kpf.springcloud.vo.KpfUserTopicListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 请求消费者
 *
 * @author shiwen
 * @date 2021/2/17
 */
@RestController
@Api(value = "用户相关接口", description = "用户相关接口") //swagger接口配置
public class UserConsumerController {

    private Logger logger = LoggerFactory.getLogger(UserConsumerController.class);

    @Autowired
    private FeignClientUserServer feignClientUserServer;

    /**
     * 获取所有用户信息
     */
    @GetMapping("/consumer/user/queryAll")
    public ResultJson<List<KpfUser>> queryAll() {
        return feignClientUserServer.queryAll();
    }

    @GetMapping("/consumer/user/queryAllMp")
    public ResultJson<List<KpfUser>> queryAll_mp() {
        return feignClientUserServer.queryAll_mp();
    }

    /**
     * 注册新用户
     */
    @PostMapping("/consumer/user/registerUser")
    public ResultJson<Boolean> registerUser(Long age, String phone, String address, String username, String password) {
        return feignClientUserServer.registerUser(age, phone, address, username, password);
    }

    /**
     * 登录接口
     */
    @GetMapping("/consumer/user/login")
    public ResultJson<KpfUser> login(String phone, String password) {
        return feignClientUserServer.login(phone, password);
    }

    /**
     * 修改个人资料
     */
    @PostMapping("/consumer/user/modifySelfInfo")
    public ResultJson<Boolean> modifySelfInfo(String headimg, String username, String phone, String password, String address) {
        return feignClientUserServer.modifySelfInfo(headimg, username, phone, password, address);
    }

    /**
     * 获取已登录的用户
     */
    @GetMapping("/consumer/user/getLoginUserById")
    public ResultJson<KpfUser> getLoginUserById() {
        return feignClientUserServer.getLoginUserById();
    }

    /**
     * 根据用户id获取用户的个人信息页面
     */
    @GetMapping("/consumer/user/getByUserId")
    public ResultJson<KpfUserTopicListVO> getByUserId() {
        return feignClientUserServer.getByUserId();
    }

    @PostMapping("/consumer/user/setSelfUserId")
    public ResultJson setSelfUserId(int userId) {
        return feignClientUserServer.setSelfUserId(userId);
    }

    @GetMapping("/consumer/user/getUserList")
    public ResultJson<PageResult> getUserList(@ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") int pageNum,
                                              @ApiParam(value = "每页数量") @RequestParam(required = false, defaultValue = "5") int pageSize) {
        return feignClientUserServer.getUserList(pageNum, pageSize);
    }

    @PostMapping("/consumer/user/deleteUserById")
    public ResultJson deleteUserById(int userId) {
        return feignClientUserServer.deleteUserById(userId);
    }

}